package com.ml.doctor.utils;

import com.ml.doctor.CustomApplication;
import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.storage.UpCompletionHandler;
import com.qiniu.android.storage.UploadManager;

import org.json.JSONObject;

import java.util.UUID;

public class QiNiuUtils {
    private UploadManager mUploadManager;
    private static QiNiuUtils mInstance;

    private QiNiuUtils(){
        mUploadManager = new UploadManager();
    }

    public static QiNiuUtils getInstance() {
        if (mInstance == null){
            mInstance = new QiNiuUtils();
        }
        return mInstance;
    }

    public String uploadImage(String token, String path){
        String key = CustomApplication.getInstance().userId + "/" + UUID.randomUUID().toString() + ".jpeg";
        mUploadManager.put(path, key, token, new UpCompletionHandler() {
            @Override
            public void complete(String key, ResponseInfo info, JSONObject response) {

            }
        }, null);
        return "";
    }

    public void uploadImage(String token, String path, UpCompletionHandler handler){
        String key = CustomApplication.getInstance().userId + "/" + UUID.randomUUID().toString() + ".jpeg";
        mUploadManager.put(path, key, token, handler, null);
    }
}
